package com.example.codelabf.dummy;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import com.example.codelabf.Constants;
import com.example.codelabf.NetworkDownloadService;

/**
 * Helper class for providing sample content for user interfaces created by
 * Android template wizards.
 * <p>
 * TODO: Replace all uses of this class before publishing your app.
 */
public class DummyContent {

    public static final String ACTION_UPDATE = "com.example.codelabf.dummy.update";

	/**
	 * An array of sample (dummy) items.
	 */
	public static List<DummyItem> ITEMS = new ArrayList<DummyItem>();

	/**
	 * A map of sample (dummy) items, by ID.
	 */
	public static Map<String, DummyItem> ITEM_MAP = new HashMap<String, DummyItem>();

	public static boolean initialized;

	static {
	    initialized = false;
	}

	public static void Init(Context context) {
	    if (!initialized) {
			// adapted from Picasa sample
			Intent initIntent = new Intent(context, NetworkDownloadService.class);
			Uri localUri = Uri.parse(Constants.PICASA_RSS_URL);
			initIntent.setData(localUri);
			context.startService(initIntent);
	        initialized = true;
	    }
	}

	private static void addItem(DummyItem item) {
		ITEMS.add(item);
		ITEM_MAP.put(item.id, item);
	}

	public static void addItem(String key, String content) {
		addItem(new DummyItem(key, content));
	}

	/**
	 * A dummy item representing a piece of content.
	 */
	public static class DummyItem {
		public String id;
		public String content;

		public DummyItem(String id, String content) {
			this.id = id;
			this.content = content;
		}

		@Override
		public String toString() {
			return content.substring(content.lastIndexOf('/')+1);
		}
	}
}
